import express from 'express';

// 引入各个模块路由
import articleRoutes from './article.js';
import commentRoutes from './comment.js'; 
import searchRoutes from './search.js';
import { selectAllCategories } from '../../controllers/categories.js';
const router = express.Router();

// 接口2: 文章类型 (/index/category)
router.get('/category', async (req, res) => {
    try {
        const categories = await selectAllCategories();
        res.json({
            code: 200,
            msg: '获取分类成功',
            data: categories.map(category => ({
                id: category.id,
                name: category.name
            }))
        });
    } catch (error) {
        console.error('获取分类失败:', error);
        res.status(500).json({
            code: 500,
            msg: '获取分类失败',
            error: error.message
        });
    }
});

// 注册子路由
router.use('/', articleRoutes);
router.use('/', commentRoutes);
router.use('/', searchRoutes);

export default router;
